#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int h[N];
int n;
bool check(int e)
{
	for (int i = 0; i < n; i++) {
		e = e * 2 - h[i];
		if (e >= 1e5)return 0;
		if (e <= 0)return 1;
	}
	return 0;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int l = 1, r = 1e5 + 1;	
	while (l + 1 < r) {
		int mid = (l + r) >> 1;
		if (check(mid))l = mid;
		else r = mid;
	}
	cout << r << endl;
	return 0;
}